//
//  BaseLoginNavgationController.m
//  CBT
//
//  Created by Mr.Zhang on 2018/11/23.
//  Copyright © 2018 Mr.Zhang. All rights reserved.
//

#import "BaseLoginNavgationController.h"

@implementation BaseLoginNavgationController

+ (void)initialize{
    
    UINavigationBar *bar = [UINavigationBar appearance];
    [bar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [bar setShadowImage:[UIImage new]];
    
    CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
    CGRect frame =CGRectMake(0, 0, ScreenNarrowSide, HFNavigationHeight);
    UIView *alphaView = [[UIView alloc] initWithFrame:CGRectMake(0, -statusBarFrame.size.height, frame.size.width, frame.size.height + statusBarFrame.size.height)];
    alphaView.backgroundColor = [UIColor whiteColor];
    [bar insertSubview: alphaView atIndex:0];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

#pragma mark --
#pragma mark -- 状态栏
- (BOOL)shouldAutorotate {
    return [self.topViewController shouldAutorotate];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return [self.topViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}
- (UIViewController *)childViewControllerForStatusBarStyle {
    return self.topViewController;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.viewControllers.count > 0){
        
        UIButton *button = [[UIButton alloc] init];
        [button setImage:[UIImage imageNamed:@"lanse_fanhui"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        button.frame=CGRectMake(0, 0, 50, StartViewHeight);
        //[button sizeToFit];
        button.backgroundColor=[UIColor clearColor];
        [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
    
    if (@available(iOS 11.0, *)){
        // 修改tabBra的frame
        CGRect frame = self.tabBarController.tabBar.frame;
        frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;
        self.tabBarController.tabBar.frame = frame;
    }
}

- (void)back{
    // 判断两种情况: push 和 present
    if ((self.presentedViewController || self.presentingViewController) && self.childViewControllers.count == 1) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }else
        [self popViewControllerAnimated:YES];
}

@end
